package game;

import game.snake.Snake;

import java.io.Serializable;
import java.util.Observable;

import javax.swing.JOptionPane;

/**
 * Player encapsulates his ID, Snake and money. 
 * 
 * @author Sarun Wongtanakarn 5510546166
 * @author Apiwat Jierakulpanit 5510546212
 * @Version 2013.04.25
 */
public class Player extends Observable implements Serializable {

	public final Integer ID;
	public final String NAME;
	private Snake snake;
	private int money;
	private int health;
	public final int MAXIMUM_HEALTH;
	
	/**
	 * Creates a new Player.
	 * 
	 * @param id Identification Number of this player.
	 * @param snake Snake of this player.
	 * @param money money of this player.
	 * @param health health of this player.
	 */
	public Player (Integer id, String name, Snake snake, int money, int health, int maxHealth) {
		ID = id;
		this.snake = snake;
		this.money = money;
		this.health = health;
		MAXIMUM_HEALTH = maxHealth;
		NAME = name;
	}
	
	/**
	 * Gets the snake of the player.
	 * @return the snake of the player.
	 */
	public Snake getSnake() {
		return snake;
	}
	
	/**
	 * Gets the amount of money owned by this player.
	 * @return the amount of money owned by this player.
	 */
	public int getMoney() {
		return money;
	}
	
	/**
	 * Gets the health of this player.
	 * @return the health of this player.
	 */
	public int getHealth() {
		return health;
	}

	/**
	 * Changes the amount of money owned by this player.  
	 * @param diff the amount of money to be added.
	 */
	public void changeMoney(int diff) {
		money = money + diff;
		setChanged();
		notifyObservers();
	}
	
	/**
	 * Changes the health of this player.  
	 * @param diff the health to be added.
	 */
	public void changeHealth(int diff) {
		health = health + diff;
		setChanged();
		notifyObservers();
		if (health > MAXIMUM_HEALTH) {
			health = MAXIMUM_HEALTH;
		}
		if (health == 0) {
			JOptionPane.showMessageDialog(null, "YOU DIE!!");
		}
	}

	/** 
	 * Sets the health of this player.
	 * @param health the new health for setting
	 */
	public void setHealth(int health) {
		this.health = health;
	}

	
}
